import { _decorator, Node, view, Vec3, Button } from 'cc';
import { Action } from '../../Action/Action';
import { ActionManager } from '../../Action/ActionManager';
import { BaseView } from '../Frame/BaseView';
const { ccclass, property } = _decorator;

@ccclass('ViewItemInfo')
export class ViewItemInfo extends BaseView {
    @property(Button)
    public buttonClose: Button;

    load() {
        this.buttonClose.node.on(Node.EventType.TOUCH_END, () => { this.exit() }, this);
    }

    onStart() {
        this.playShowAction();
    }

    playShowAction() {
        ActionManager.instance.playEvent("show", false, undefined, (action: Action) => {
            let size = view.getCanvasSize();
            let randomX = this.randomValue(-size.x, size.x);
            let randomY = this.randomValue(-size.y, size.y);
            action.positionProp.valueFrom = new Vec3(randomX, randomY, 0);
        });
    }

    randomValue(min: number, max: number) {
        let dis = max - min;
        return min + Math.floor(Math.random() * dis);
    }
}